﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Addmin/BackEnd/MTP_Admin.Master" ValidateRequest="false" 
    AutoEventWireup="true" CodeBehind="MG_Artical.aspx.cs" Inherits="KiwiShopping.Addmin.BackEnd.MG_Artical" %>
<%@ Register Assembly="CKEditor.NET" Namespace="CKEditor.NET" TagPrefix="CKEditor" %>


<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<script src="/ckeditor/ckeditor.js" type="text/javascript"></script>
<ext:Panel ID="Panel3" runat="server" Title="Quản lý Bài viết" Icon="Application" 
                             PaddingSummary="10px 5px 0 5px" Layout="FormLayout">
                            <Items>
    <ext:TabPanel ID="TabPanel1" runat="server"  Border="false" >
        <Items>
            
            <ext:Panel ID="Panel1" runat="server" Title="Chi tiết bài viết" Height="500" >
                <Content >
                <table>
                    <tr>
                        <td style="width:10%">Tiêu đề</td>
                        <td style="width:10%"><ext:TextField ID="dt_title" runat="server" Width="200" /></td>
                        <td style="width:2%"></td>
                        <td style="width:15%">Ảnh đại diện(URL)</td>
                        <td ><ext:TextField ID="dt_image" runat="server" Width="250" /></td>
                        <ext:Hidden ID="dt_ID" runat="server"></ext:Hidden>
                    </tr>
                    <tr>
                        <td >DM cha</td>
                        <td >
                             <ext:SelectBox ID="DMCha" runat="server"  AnchorHorizontal="100%"  OnDirectSelect="SelectParent"  
                                                    DataIndex="Status" IDMode="Static" ValueField="ID" DisplayField="Name">
                                                    <Store>
                                                        <ext:Store ID="DMCha_Store" runat="server">
                                                            <Reader>
                                                                <ext:ArrayReader IDProperty="ID">
                                                                    <Fields>
                                                                        <ext:RecordField Name="ID" Type="int" Mapping="ID" />
                                                                        <ext:RecordField Name="Name" Type="String" Mapping="Name" />
                                                                    </Fields>
                                                                </ext:ArrayReader>
                                                            </Reader>
                                                        </ext:Store>
                                                    </Store>
                                                </ext:SelectBox>
                        </td>
                        <td ></td>
                        <td >DM con</td>
                        <td >
                             <ext:SelectBox ID="DMCon" runat="server"  AnchorHorizontal="100%"
                                                    DataIndex="Status" IDMode="Static" ValueField="ID" DisplayField="Name">
                                                    <Store>
                                                        <ext:Store ID="DMCon_Store" runat="server">
                                                            <Reader>
                                                                <ext:ArrayReader IDProperty="ID">
                                                                    <Fields>
                                                                        <ext:RecordField Name="ID" Type="int" Mapping="ID" />
                                                                        <ext:RecordField Name="Name" Type="String" Mapping="Name" />
                                                                    </Fields>
                                                                </ext:ArrayReader>
                                                            </Reader>
                                                        </ext:Store>
                                                    </Store>
                                                </ext:SelectBox>
                        </td>
                    </tr>
                    <tr>
  
                        <td>Giới thiệu</td>
                        <td colspan="4"><ext:TextArea ID="dt_gioithieu" runat="server" Width="600"/></td>
                    </tr>
                    <tr>
  
                        <td>Trang chủ</td>
                        <td colspan="4"><ext:Checkbox runat="server" ID="isBanner" /></td>
                    </tr>
                    <tr>
                        <td colspan="5">Nội dung</td>
                    </tr>
                    <tr>
                        <td colspan="5"><CKEditor:CKEditorControl ID="dt_content" runat="server" Language="vi"></CKEditor:CKEditorControl></td>
                        <ext:Hidden ID="dt_content2" runat="server"></ext:Hidden>
                    </tr>
                   
                </table>                 
                </Content>
                 <Buttons>

                            <ext:Button ID="Button1" Text="Thêm mới" Icon="Reload" runat="server" >
                                   <Listeners>
                                    <Click Fn="reset" />
                                    </Listeners>
                                </ext:Button>

                                <ext:Button ID="btn_Save" Text="Lưu" Icon="Add" runat="server" >
                                   <DirectEvents >
                                    <Click OnEvent="Save" Before="Set_Content" > 
                                    </Click>
                                   </DirectEvents>
                                </ext:Button>
                    </Buttons>
            </ext:Panel>
            <ext:Panel ID="Panel2" runat="server" Title="Danh sách bài viết">
                 <Items>
            <ext:FieldSet ID="FieldSet1" runat="server" Layout="ColumnLayout" Title="Thông tin tìm kiếm"
                PaddingSummary="10px 5px 0 5px" Height="120">
                <Items>
                    <ext:Container ID="Container2" runat="server" LabelAlign="Right" Layout="FormLayout"
                        ColumnWidth=".5">
                        <Items>
                            <ext:TextField ID="tk_title" runat="server" FieldLabel="Tiêu đề" AnchorHorizontal="100%"
                                LabelAlign="Right" IDMode="Static" />
                        </Items>
                        <Items>
                            <ext:DateField runat="server" ID="tk_Ngaybd" IDMode="Static" FieldLabel="Từ ngày"
                                AnchorHorizontal="100%" />
                        </Items>
                        <Items>
                            <ext:DateField runat="server" ID="tk_Ngaykt" IDMode="Static" FieldLabel="Đến ngày"
                                AnchorHorizontal="100%" />
                        </Items>
                    </ext:Container>
                    <ext:Container ID="Container3" runat="server" LabelAlign="Right" Layout="FormLayout"
                        ColumnWidth=".5">
                        <Items>
                            <ext:SelectBox ID="tk_DMCon_Grid" runat="server" FieldLabel="Danh mục" AnchorHorizontal="100%"
                                DataIndex="Status" IDMode="Static" ValueField="ID" DisplayField="Name">
                                <Store>
                                    <ext:Store ID="tk_DMCon_Store" runat="server">
                                        <Reader>
                                            <ext:ArrayReader IDProperty="ID">
                                                <Fields>
                                                    <ext:RecordField Name="ID" Type="int" Mapping="ID" />
                                                    <ext:RecordField Name="Name" Type="String" Mapping="Name" />
                                                </Fields>
                                            </ext:ArrayReader>
                                        </Reader>
                                    </ext:Store>
                                </Store>
                            </ext:SelectBox>
                        </Items>
                        <Items>
                            <ext:Button ID="Button3" runat="server" Text="Tìm kiếm" FieldLabel=" " LabelSeparator=" "
                                Icon="Find">
                                <DirectEvents >
                                    <Click OnEvent="Search"  > 
                                    </Click>
                                   </DirectEvents>
                            </ext:Button>
                        </Items>
                    </ext:Container>
                </Items>
            </ext:FieldSet>
        </Items>
        <Items>
            <ext:GridPanel ID="Artical_Grid" IDMode="Static" runat="server" Height="300" AutoScroll="true"
                Region="Center">
                <Store>
                    <ext:Store ID="Artical_Store" runat="server" AutoDataBind="true" SkipIdForNewRecords="false">
                        <Reader>
                            <ext:JsonReader IDProperty="ID">
                                <Fields>
                                    <ext:RecordField Name="ID" Type="String" Mapping="ID" />
                                    <ext:RecordField Name="Title" Type="String" Mapping="Title" />
                                    <ext:RecordField Name="SubContent" Type="String" Mapping="SubContent" />
                                    <ext:RecordField Name="Date" Type="Date" Mapping="Date" />
                                </Fields>
                            </ext:JsonReader>
                        </Reader>
                    </ext:Store>
                </Store>
                <ColumnModel ID="ColumnModel2" runat="server" AutoDataBind="true">
                    <Columns>
                        <ext:RowNumbererColumn />
                        <ext:Column ColumnID="ID" Header="Mã" DataIndex="ID" Hidden="true" />
                        <ext:Column Header="Tiêu đề" DataIndex="Title" AutoDataBind="true" Width="70" MenuDisabled="True" />
                        <ext:Column Header="Giới thiệu" DataIndex="SubContent" AutoDataBind="true" Width="150" />
                        <ext:DateColumn Header="Ngày cập nhật" DataIndex="Date" AutoDataBind="true"
                            MenuDisabled="True" Format="dd/MM/yyyy" />
                        <ext:CommandColumn Header="Action">
                            <Commands>
                                <ext:GridCommand Icon="Delete" CommandName="Delete" ToolTip-Text="Xóa">
                                </ext:GridCommand>
                                <ext:CommandSeparator />
                                <ext:GridCommand Icon="NoteEdit" CommandName="Edit" ToolTip-Text="Sửa/Xem" />
                            </Commands>
                        </ext:CommandColumn>
                    </Columns>
                </ColumnModel>
                <BottomBar>
                    <ext:PagingToolbar ID="PagingToolBar1" runat="server" PageSize="20" StoreID="Artical_Store"
                        DisplayInfo="false" />
                </BottomBar>
                <SelectionModel>
                    <ext:RowSelectionModel runat="server" ID="RowSelectionModel1">
                    </ext:RowSelectionModel>
                </SelectionModel>
                <Listeners>
                    <Command Handler="detail(command, record.data.ID)" />
                </Listeners>
            </ext:GridPanel>
        </Items>
            </ext:Panel>
            </Items>

    </ext:TabPanel>

    </Items>
    </ext:Panel>

    <script language="javascript">
        function Set_Content() {
            var content = CKEDITOR.instances['<%= dt_content.ClientID %>'].getData();
            Ext.getCmp('<%= dt_content2.ClientID %>').setValue(content);
        }

        function setValueFCK() {
            var content = Ext.getCmp('<%= dt_content2.ClientID %>').getValue();
            CKEDITOR.instances['<%= dt_content.ClientID %>'].setData(content);
            
        }

        function detail(command, id) {
            if (command == 'Delete') {
                Ext.MessageBox.confirm('Chú ý', 'Bạn có muốn xóa Bài viết này không?',
                    function (btn) {
                        if (btn == 'yes') {
                               //window.location = "MG_Artical.aspx?Action=" + command + "&ID=" + id;   
                                Ext.net.DirectMethod.request({
                                    url: "MG_Artical.aspx",
                                    cleanRequest: true,
                                    params: {
                                        Action: command,
                                        ID: id
                                    }
                                });
                        }
                        else
                            return false;
                    });

            } else {
//                window.location = "MG_Artical.aspx?Action=" + command + "&ID=" + id;
                    Ext.net.DirectMethod.request({
                        url: "MG_Artical.aspx",
                        cleanRequest: true,
                        params: {
                            Action: command,
                            ID: id
                        }
                    });

                }
        }



function reset() {
    Ext.getCmp('<%= dt_title.ClientID %>').setValue("");
    Ext.getCmp('<%= dt_image.ClientID %>').setValue("");
    Ext.getCmp('<%= dt_ID.ClientID %>').setValue("");
    Ext.getCmp('<%= dt_gioithieu.ClientID %>').setValue("");
    Ext.getCmp('<%= dt_content2.ClientID %>').setValue("");
    CKEDITOR.instances['<%= dt_content.ClientID %>'].setData("");

    
}
    </script>
</asp:Content>
